package com.bitdf.txing.product.controller;

import cn.dev33.satoken.annotation.SaCheckLogin;
import cn.dev33.satoken.annotation.SaCheckPermission;
import com.bitdf.txing.common.utils.R;
import com.bitdf.txing.product.entity.AttrAttrgroupRelationEntity;
import com.bitdf.txing.product.service.AttrAttrgroupRelationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Arrays;


/**
 * 属性&属性分组关联
 *
 * @author lizhiwei
 * @date 2022-05-16 20:22:24
 */
@RestController
@RequestMapping("${txing.request.path.product}/attrattrgrouprelation")
public class AttrAttrgroupRelationController {
    @Autowired
    private AttrAttrgroupRelationService attrAttrgroupRelationService;

    /**
     * 列表
     */
//    @RequestMapping("/list")
//    public R list(@RequestParam Map<String, Object> params, HttpSession session, HttpServletRequest request, HttpServletResponse response){
////        System.out.println(session.getId());
////        Cookie cookie = new Cookie("GULISESSION", session.getId());
////        cookie.setPath("/");
////        response.addCookie(cookie);
//        PageUtils page = attrAttrgroupRelationService.queryPage(params);
//
//        return R.ok().put("page", page);
//    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") Long id){
		AttrAttrgroupRelationEntity attrAttrgroupRelation = attrAttrgroupRelationService.getById(id);

        return R.ok().put("attrAttrgroupRelation", attrAttrgroupRelation);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @SaCheckLogin
    @SaCheckPermission("mall:product:attr:group:relate:add")
    public R save(@RequestBody AttrAttrgroupRelationEntity attrAttrgroupRelation){
		attrAttrgroupRelationService.save(attrAttrgroupRelation);

        return R.ok();
    }

    /**
     * 修改
     */
    @SaCheckLogin
    @SaCheckPermission("mall:product:attr:group:relate:update")
    @RequestMapping("/update")
    public R update(@RequestBody AttrAttrgroupRelationEntity attrAttrgroupRelation){
		attrAttrgroupRelationService.updateById(attrAttrgroupRelation);

        return R.ok();
    }

    /**
     * 删除
     */
    @SaCheckLogin
    @SaCheckPermission("mall:product:attr:group:relate:delete")
    @RequestMapping("/delete")
    public R delete(@RequestBody Long[] ids){
		attrAttrgroupRelationService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
